<?php

class MemberController extends GTL_Action {

    public function init() {
        parent::init();
        $this->lng_id = '1';
       
        /* Initialize action controller here */
    }

    public function indexAction() {
        $this->_helper->redirector('form', 'member', 'default');
    }

    public function uploadAction() {

        $upload = new Zend_File_Transfer_Adapter_Http();

        foreach ($upload->getFileInfo() as $fields => $asFileInfo) {

            if ($asFileInfo['name'] != '') {
                switch ($fields) {
                    
                    case "DOCUMENT":
                        $folder = $this->config->UPLOAD_PATH . "member/document/";
                        break;
                }

                if ($this->getRequest()->isPost()) {

                    $postedData = $this->_request->getPost();
                    if ($postedData['UNIQUEIDENTIFIER'] != '') {
                        $upload->setDestination($folder);
                        $originalFilename = pathinfo($asFileInfo['name']);
                        $file_name = preg_replace("/[^-_a-zA-Z0-9]+/i", "_", $originalFilename['filename']) . '_' . time() . '.' . $originalFilename['extension'];
                        $upload->addFilter('Rename', $file_name, 'filename');
                        $upload->receive($fields);


                        if ($fields == 'DOCUMENT') {
                            $memberDocumentModel = new Model_Memberdocument();
                            $memberDocData = Array();
                            $memberDocData['mem_id'] = '';
                            $memberDocData['memd_doc'] = $file_name;
                            $memberDocData['memd_type'] = $fields;
                            $memberDocData['memd_identifier'] = $postedData['UNIQUEIDENTIFIER'];
                            $memberDocData['memd_createddate'] = date('Y-m-d H:i:s');
                            $memberDocumentModel->save($memberDocData, 'memd_id');
                        } 
                    }
                }
            }
        }


        exit;
    }

    public function listAction(){
        
        
        $errorMessage = Array();
        $successmessage = "";
        $where = "usr.member_publish = '1' and md.member_publish = '1' ";
        $orderField = 'usr.member_id';
        $sort = 'asc';
        
        /* Pagination Login */
        $itemsPerPageReviews = $this->config->PAGING_PER_PAGE;
        $currentPageReviews = 1;
        
        //PAGING_PER_PAGE

        if ($this->_getParam('page') && $this->_getParam('page') != "") {
            $currentPageReviews = $this->_getParam('page');
        }

        if ($this->_getParam('field') && $this->_getParam('field') != "") {
            $orderField = $this->_getParam('field');
        }

        if ($this->_getParam('sort') && $this->_getParam('sort') != "") {
            $sort = $this->_getParam('sort');
        }

        $offset = ($currentPageReviews - 1) * $itemsPerPageReviews;
        $memberModel = new Model_Member();
        
        $memberData = $memberModel->fetchMemberAllData($where, $itemsPerPageReviews, $offset, $orderField, $sort);
       // echo 'in';exit;
        $paginator = new GTL_Paginator();
        $paginator->setItemsPerPage($itemsPerPageReviews);
        $paginator->setItemsTotal($memberModel->getMemberCount($where));
        $paginator->setCurrentPage($currentPageReviews);
        $link = $this->view->url(array('controller' => 'member', 'action' => 'list', 'page' => 'PAGENO'), 'default', false);
        $paginator->paginate($link);

        $this->view->paginator = $paginator;
        $this->view->memberData = $memberData;
        $this->view->errorMessage = $errorMessage;
        $this->view->successmessage = $successmessage;

    }


    public function formAction() {
        $uniqueId = uniqid('unq_');

        $successmessage = "";
        $memberDocuments = "";
        $mem_description = "";
        $errorMessageArray = Array();
        $this->view->mode = "Add";
        $data = Array();
        
        
       
        
        $memberModel = new Model_Member();
        $memberForm = new Form_Member();
        $memberDocumentModel = new Model_Memberdocument();
        $memberDetailsModel = new Model_Memberdetails();
        
        $cityModel = new Model_City();
         
        $propertyDocuments = $memberDocumentModel->fetchMemberDocumentsByMemberId();
        
        //Load prefix select box
        
        $prefixArray = $memberModel->fetchprefixData();
        $memberForm->mem_prefix->addMultiOptions($prefixArray);
     
        //load Company Type in select box
        
        $companyTypeData = $memberModel->fetchCompanyData();
        $memberForm->mem_company_type->addMultiOptions($companyTypeData);
        
        
        //load Client Type in select box
        
        $clientTypeData = $memberModel->fetchClientData();
       // $memberForm->mem_client_type->addMultiOptions($clientTypeData);
        
        //load Client Status in select box
        
        $clientStatusData = $memberModel->fetchClientStatusData();
        $memberForm->mem_client_status->addMultiOptions($clientStatusData);
        
        //Load Member select box
        
        $memberArray = $memberModel->fetchMemberData();
        $memberForm->client_referral_name->addMultiOptions($memberArray);
        
        //Load country select box
        $countryModel = new Model_Country();
        $countryArray = $countryModel->fetchCountry("country_lang_id = '" . $this->lng_id . "'");
        $memberForm->mem_country->addMultiOptions($countryArray);
        
        
        $MemberData['member_id'] = $this->_request->getParam('member_id');
        $member_id = (!empty($MemberData['member_id'])) ? $MemberData['member_id'] : null;
        $usertypeModel =new Model_Usertype();
                    


        
        if (!empty($member_id)) {
            //Set the Mode to Edit
            $this->view->mode = "Edit";

            //Fetch data to be loaded in form 
            $data = $memberModel->fetchEntryById($member_id);
            $member_usertype = $usertypeModel->fetchAllUsertype("ut_mem_id = ".$member_id);
            $this->view->member_usertype = $member_usertype;
            $cityArray = $cityModel->fetchCity("city_lang_id = '" . $this->lng_id . "' and country_id = '" . $data['mem_country'] . "'");
           // member_usertype
            
            $memberForm->mem_city->addMultiOptions($cityArray);
            $mem_description = $data['mem_description'];
           // if ($data['mem_client_type'] == 'buyer' || $data['mem_client_type'] == 'tenant') {
              if(array_key_exists('buyer', array_flip($member_usertype)) || 
                array_key_exists('tenant', array_flip($member_usertype))    ){
                  
                $clientStatusData = $memberModel->fetchClientStatusData();
                $memberForm->mem_client_status->addMultiOptions($clientStatusData);
                $this->view->show_client_status = 1;
            }
            
            if ($data['mem_client_status'] == 'pending' || $data['mem_client_status'] == 'incubated') {
                $this->view->show_client_datepicker = 1;
            }
            
            $memberDocuments = $memberDocumentModel->fetchMemberDocumentsByMemberId($member_id);
            
            $this->view->member_admin = $data['member_admin'];
            $this->view->profile_image = $data['profile_image'];
            
        }
       
         $this->view->form = $memberForm->populate($data);
         if ($this->getRequest()->isPost()) {
              //Check for Errors
            $postedData = $this->_request->getPost();
            if(array_key_exists('mem_client_type', $postedData)){
                $this->view->member_usertype = $postedData['mem_client_type'];
            }
            if ($postedData['UNIQUEIDENTIFIER'] != '') {
                $uniqueId = $postedData['UNIQUEIDENTIFIER'];
            }
            if ($postedData['mem_country'] != '') {
                $cityArray = $cityModel->fetchCity("city_lang_id = '" . $this->lng_id . "' and country_id = '" . $postedData['mem_country'] . "'");
                $memberForm->mem_city->clearMultiOptions();
                $memberForm->mem_city->addMultiOptions($cityArray);
            }
            
            if(array_key_exists('buyer', array_flip($postedData['mem_client_type'])) || 
                array_key_exists('tenant', array_flip($postedData['mem_client_type']))    ){
                $clientStatusData = $memberModel->fetchClientStatusData();
                $memberForm->mem_client_status->addMultiOptions($clientStatusData);
                $this->view->show_client_status = 1;
            }
            
           /* if ($postedData['mem_client_type'] == 'buyer' || $postedData['mem_client_type'] == 'tenant') {
                
                $clientStatusData = $memberModel->fetchClientStatusData();
                $memberForm->mem_client_status->addMultiOptions($clientStatusData);
                $this->view->show_client_status = 1;
            }*/
            
            if ($postedData['mem_client_status'] == 'pending' || $postedData['mem_client_status'] == 'incubated') {
                $this->view->show_client_datepicker = 1;
            }
            if(array_key_exists('mem_description', $postedData)){
                $mem_description = $postedData['mem_description'];
            }
            
            
            
             
            if (!$memberForm->isValid($postedData)) {
               $errorMessage = $memberForm->getMessages();
                foreach ($errorMessage as $_err) {
                    foreach ($_err as $_val) {
                        $errorMessageArray[] = $_val;
                    }
                }
            }else{
                if (count($errorMessageArray) > 0) {
                    
                }else {
                    
                    /*$member_username = $postedData['member_username'];
                    if ($member_username == '') {
                        $usernameArray = explode("@", $postedData['member_email']);
                        $member_username = $usernameArray['0'];
                    }*/

                    $upload = new Zend_File_Transfer_Adapter_Http();
                    foreach ($upload->getFileInfo() as $fields => $asFileInfo) {
                        if ($asFileInfo['name'] != '') {
                            $folder = $this->config->UPLOAD_PATH . "member/profile/";
                            $upload->setDestination($folder);
                            $originalFilename = pathinfo($asFileInfo['name']);
                            $fileName = preg_replace("/[^-_a-zA-Z0-9]+/i", "_", $originalFilename['filename']) . '_' . time() . '.' . $originalFilename['extension'];
                            $upload->addFilter('Rename', $fileName, 'filename');
                            $upload->receive($fields);
                            
                        }
                    }
                    
                    
                    ##Phone Logic ##Phone Logic
                    //Check for the email exist while Adding custoemr
                    $memberExist = $memberModel->checkEmailExist($postedData['member_email']);
                    $phoneExist = $memberModel->checkPhoneExist($postedData['member_phone']);
                    

                    if ($phoneExist) {
                        
                        //If phone number exist
                        $emailExist = $memberModel->checkEmailExist($postedData['member_email']);

                        if ($phoneExist->member_email == $postedData['member_email']) {
                            //User exist and assign that user to it

                            $memberData = Array();
                           // $memberData['member_username'] = $member_username;
                            $memberData['member_id'] = $phoneExist->member_id;
                            $memberData['member_phone'] = $postedData['member_phone'];
                            $memberData['member_admin'] = $postedData['member_admin'];
                            
                            $memberModel->save($memberData, 'member_id');

                            $member_id = $phoneExist->member_id;
                            $memberDetailsArray['memd_id'] = $phoneExist->memd_id;
                            $memberDetailsArray['client_id'] = $phoneExist->memd_id;
                            
                            if ($this->view->mode == "Add") {
                                $memberDetailsArray['mem_registration_date'] = date("Y-m-d H:i:s");
                            }
                            if($fileName != ''){
                                    $memberDetailsArray['profile_image'] = $fileName;
                            }
                            $memberDetailsArray['mem_updated_by'] = $this->USER->member_id;
                            $memberDetailsArray['mem_update_date'] = date("Y-m-d H:i:s");
                            $memberDetailsArray['mem_prefix'] = $postedData['mem_prefix'];
                            $memberDetailsArray['mem_company_name'] = $postedData['mem_company_name'];
                            $memberDetailsArray['mem_company_type'] = $postedData['mem_company_type'];
                          //  $memberDetailsArray['mem_client_type'] = $postedData['mem_client_type'];
                            $memberDetailsArray['mem_client_status'] = $postedData['mem_client_status'];
                            $memberDetailsArray['mem_client_calender'] = $postedData['mem_client_calender'];
                            $memberDetailsArray['mem_client_note'] = $postedData['mem_client_note'];
                            $memberDetailsArray['mem_bday'] = $postedData['mem_bday'];
                            $memberDetailsArray['mem_name'] = $postedData['mem_name'];
                            $memberDetailsArray['mem_address'] = $postedData['mem_address'];
                            $memberDetailsArray['mem_surname'] = $postedData['mem_surname'];
                            $memberDetailsArray['mem_country'] = $postedData['mem_country'];
                            $memberDetailsArray['mem_city'] = $postedData['mem_city'];
                            $memberDetailsArray['mem_mobile'] = $postedData['mem_mobile'];
                            $memberDetailsArray['mem_landline'] = $postedData['mem_landline'];
                            $memberDetailsArray['mem_work'] = $postedData['mem_work'];
                            $memberDetailsArray['mem_representative_name1'] = $postedData['mem_representative_name1'];
                            $memberDetailsArray['mem_representative_telephone1'] = $postedData['mem_representative_telephone1'];
                            $memberDetailsArray['mem_representative_email1'] = $postedData['mem_representative_email1'];
                            $memberDetailsArray['mem_representative_name2'] = $postedData['mem_representative_name2'];
                            $memberDetailsArray['mem_representative_telephone2'] = $postedData['mem_representative_telephone2'];
                            $memberDetailsArray['mem_representative_email2'] = $postedData['mem_representative_email2'];
                            $memberDetailsArray['mem_representative_name3'] = $postedData['mem_representative_name3'];
                            $memberDetailsArray['mem_representative_telephone3'] = $postedData['mem_representative_telephone3'];
                            $memberDetailsArray['mem_representative_email3'] = $postedData['mem_representative_email3'];
                            $memberDetailsArray['mem_description'] = $postedData['mem_description'];
                            $memberDetailsArray['client_referral_name'] = $postedData['client_referral_name'];
                            $memberDetailsArray['member_publish'] = 1;
                            
                            
                            
                            $memberDetailsArray['member_id'] = $member_id;
                            $memberDetailsModel->save($memberDetailsArray, 'memd_id');
                        } 
                        else {
                            
                            //Show error message that this phone already exists and is linked with another email and cannot be linked to entered email
                            $errorMessageArray[] = 'Phone already exists and is linked with another email and cannot be linked to entered email';
                        }
                    } 
                    else {
                       
                        //If phone number donot exist
                        $emailExist = $memberModel->checkEmailExist($postedData['member_email']);
                        if ($emailExist) {
                            //Show error message this email is linked with another phone number, so try another email
                            $errorMessageArray[] = 'Entered email is linked with another phone number, so try another email';
                        } else {
                            
                            //Write down the code to insert and add new member

                            $memberData = Array();
                            $generatedPasswrod = GTL_Common::generatePassword();
                            $usernameArray = explode("@", $postedData['member_email']);
                            $member_username = $usernameArray['0'];
                            $memberData['member_username'] = $member_username;
                            $memberData['member_admin'] = $postedData['member_admin'];
                            $memberData['member_email'] = $postedData['member_email'];
                            $memberData['member_password'] = md5($postedData['member_password']);//md5($generatedPasswrod);
                            $memberData['member_admin'] = 0;
                            $memberData['member_phone'] = $postedData['member_phone'];
                            $memberData['member_forgot'] = "";
                            $memberData['oauth_provider'] = "0";
                            $memberData['oauth_access_token'] = "";
                            $memberData['oauth_user_key'] = "";
                            $memberData['member_admin_level'] = "1";
                            $memberData['member_publish'] = 1;

                            $member_id = $memberModel->save($memberData, 'member_id');
                           
                            if ($member_id > 0) {
                            
                                $memberDetailsArray = Array();
                                if ($this->view->mode == "Add") {
                                    $memberDetailsArray['mem_registration_date'] = date("Y-m-d H:i:s");
                                }
                                if($fileName != ''){
                                    $memberDetailsArray['profile_image'] = $fileName;
                                }
                                $memberDetailsArray['mem_updated_by'] = $this->USER->member_id;
                                $memberDetailsArray['mem_update_date'] = date("Y-m-d H:i:s");
                                $memberDetailsArray['mem_prefix'] = $postedData['mem_prefix'];
                                $memberDetailsArray['mem_company_name'] = $postedData['mem_company_name'];
                                $memberDetailsArray['mem_company_type'] = $postedData['mem_company_type'];
                             //   $memberDetailsArray['mem_client_type'] = $postedData['mem_client_type'];
                                $memberDetailsArray['mem_client_status'] = $postedData['mem_client_status'];
                                $memberDetailsArray['mem_client_calender'] = $postedData['mem_client_calender'];
                                $memberDetailsArray['mem_client_note'] = $postedData['mem_client_note'];
                                $memberDetailsArray['mem_bday'] = $postedData['mem_bday'];
                                $memberDetailsArray['mem_title'] = "";
                                $memberDetailsArray['mem_name'] = $postedData['mem_name'];
                                $memberDetailsArray['mem_address'] = $postedData['mem_address'];
                                $memberDetailsArray['mem_surname'] = $postedData['mem_surname'];
                                $memberDetailsArray['mem_country'] = $postedData['mem_country'];
                                $memberDetailsArray['mem_city'] = $postedData['mem_city'];
                                $memberDetailsArray['mem_mobile'] = $postedData['mem_mobile'];
                                $memberDetailsArray['mem_landline'] = $postedData['mem_landline'];
                                $memberDetailsArray['mem_work'] = $postedData['mem_work'];
                                $memberDetailsArray['mem_fax'] = $postedData['mem_fax'];
                                $memberDetailsArray['mem_representative_name1'] = $postedData['mem_representative_name1'];
                                $memberDetailsArray['mem_representative_telephone1'] = $postedData['mem_representative_telephone1'];
                                $memberDetailsArray['mem_representative_email1'] = $postedData['mem_representative_email1'];
                                $memberDetailsArray['mem_representative_name2'] = $postedData['mem_representative_name2'];
                                $memberDetailsArray['mem_representative_telephone2'] = $postedData['mem_representative_telephone2'];
                                $memberDetailsArray['mem_representative_email2'] = $postedData['mem_representative_email2'];
                                $memberDetailsArray['mem_representative_name3'] = $postedData['mem_representative_name3'];
                                $memberDetailsArray['mem_representative_telephone3'] = $postedData['mem_representative_telephone3'];
                                $memberDetailsArray['mem_representative_email3'] = $postedData['mem_representative_email3'];
                                $memberDetailsArray['mem_description'] = $postedData['mem_description'];
                                $memberDetailsArray['client_referral_name'] = $postedData['client_referral_name'];
                                //$memberDetailsArray['mem_bday'] = date('Y-m-d');
                                $memberDetailsArray['member_id'] = $member_id;
                                $memberDetailsArray['client_id'] = $member_id;
                                $memberDetailsArray['member_publish'] = 1;
                                //echo $member_id."====".$uniqueId;exit;
                                $memberDetailsModel->save($memberDetailsArray, 'memd_id');
                                
                                

                            }
                        }
                    }
                    
                    $usertypeModel->delete("ut_mem_id = '" . $member_id . "'");
                    foreach($postedData['mem_client_type'] as $key =>$value){
                        $client_type = array();
                        $client_type['ut_mem_id'] = $member_id;
                        $client_type['ut_type'] = $value;
                        $usertypeModel->save($client_type, 'ut_id');
                    }
                    
                    
                   // echo $member_id;exit;
                                $memberDocumentModel->update(Array('mem_id' => $member_id), "memd_identifier = '" . $uniqueId . "'");
                                
                                if (count($errorMessageArray) > 0) {
                                    
                                }else{
                                    if($postedData['member_password'] != ""){
                                        //mail send
                                   
                                        $body = "<html>
				<head>
				</head>
				<body>
				<table style='width:50%'>
				    <tr>
				    <td>
				    <p>Hello user</p>
				    <p>New password for your LTADMIN!</p>
				    <table border='1' cellpadding='10'>
					    <tr>
						    <td>Email Address</td>
						    <td width='80px' align='center'>" . $postedData['member_email'] . "</td>
					    </tr>
					    <tr>
						    <td>Password</td>
						    <td>" . $postedData['member_password'] . "</td>
					    </tr>
                                           
				    </table>
                                    <p>
                                        Please click on below link and login into system with this email and password.
                                        <br/>
                                        ".$this->view->BASE_URL."login
                                    </p>
				    <p>
				    Thanks,<br/>
				    The Admin Team
				    </p>
				     </td>
				    </tr>
				</table>
				</body>
				</html>
				";
                                        $ADMIN_MAIL = "wikitudedev@gmail.com";
                                        $mail = new Zend_Mail();
                                        $mail->setBodyText($body);
                                        $mail->setBodyHtml($body, "iso-8859-1");
                                        $mail->addTo($ADMIN_MAIL, 'LTADMIN');
                                        $mail->setReplyTo($ADMIN_MAIL, 'LTADMIN');
                                        $mail->addTo($postedData['member_email'], 'LTADMIN');
                                        $mailSubject = "Password Detail";
                                        $mail->addHeader('MIME-Version', '1.0');
                                        $mail->addHeader('Content-Transfer-Encoding', '8bit');
                                        $mail->addHeader('X-Mailer:', 'PHP/' . phpversion());
                                        $mail->setSubject($mailSubject);
                                        
                                         try {
                                            $mail->send();
                                          //  $successmessage = "New password is sent to your email.";
                                        } catch (Zend_Exception $e) {
                                           // $frgtPwdForm->addErrorMessage("Due to technical problem, email has not been sent. Please try later or contact webmaster.");
                                           // $errorMessage['0'] = $frgtPwdForm->getErrorMessages();
                                        }
                                    }
                                    
                                    if ($this->view->mode == "Add") {
                                        $successmessage = 'Member add successfully';
                                    } else {
                                        $successmessage = 'Member updated successfully';
                                    }
                                    $this->addSuccessMessage($successmessage);
                                    $this->_helper->redirector('list', 'member', '');
                                }
                }
            }
            
            
         }
        
        $this->view->clientTypeData = $clientTypeData;  
        $this->view->mem_description =$mem_description;
        $this->view->memberDocuments = $memberDocuments;
        $this->view->UNIQUEIDENTIFIER = $uniqueId;
        $this->view->errorMessageArray = $errorMessageArray;
        $this->view->succesMessage = $successmessage;
        $this->view->mode = $this->view->mode;
        $this->view->form = $memberForm;
    }
    public function getcitylistAction() {
        $cityString = "<option>-- Select City--</option>";
        if ($this->getRequest()->isPost()) {
            $postedData = $this->_request->getPost();
            if ($postedData['country_id'] != '') {

                $cityModel = new Model_City();
                $cityArray = $cityModel->fetchCity("city_lang_id = '" . $this->lng_id . "' and country_id = '" . $postedData['country_id'] . "'");

                if (count($cityArray) > 0) {
                    $cityString = "";
                    foreach ($cityArray as $city_id => $_city_title) {
                        $cityString .= "<option value='" . $city_id . "'>" . $_city_title . "</option>";
                    }
                }
            }
        }
        echo $cityString;
        exit;
    }
   
     public function deleteimageAction() {

        $memberModel = new Model_Member();
        $memberdocuments = new Model_Memberdocument();

        $type = "";
        if ($this->_getParam('type') && $this->_getParam('type') != "") {
            $type = $this->_getParam('type');
        }

        if ($type == '') {
            $this->_helper->redirector('list', 'member', '');
            exit;
        }

        if ($this->_getParam('id') && $this->_getParam('id') != "") {
            $id = $this->_getParam('id');
        }

        if ($type == 'DOCUMENT') {
            if ($this->_getParam('id') && $this->_getParam('id') != "") {
                $id = $this->_getParam('id');
                $documents = $memberdocuments->fetchEntryById($id);
                $memberdocuments->delete("memd_id = '" . $id . "'");
                $folder = $this->config->UPLOAD_PATH . "member/document/";
                $targetPath = $folder . $documents['memd_doc'];
                if (file_exists($targetPath)) {
                    unlink($targetPath);
                }
                $successmessage = "Member document deleted successfully";
                $this->addSuccessMessage($successmessage);
                $this->_helper->redirector('list', 'member', '');
                exit;
            }
        } 
       
    }
    
    
     public function archiveAction() {

        $memberModel = new Model_Member();
        $memberDetailModel =new Model_Memberdetails();

        if ($this->_getParam('member_id') && $this->_getParam('member_id') != "") {
            $member_id = $this->_getParam('member_id');
            $memberData = Array();
            $memberData['member_id'] = $member_id;
            $memberData['member_publish'] = '0';
            $memberModel->save($memberData, 'member_id');

            
            $memberdetailData = Array();
            $memberdetailData['member_id'] = $member_id;
            $memberdetailData['member_publish'] = '0';
            $memberDetailModel->save($memberdetailData, 'member_id');
            
            $successmessage = "Member archived successfully";
            $this->addSuccessMessage($successmessage);
            $this->_helper->redirector('list', 'member', '');
            exit;
        }
    }

    public function deleteAction() {


        if ($this->_getParam('member_id') && $this->_getParam('member_id') != "") {
            $member_id = $this->_getParam('member_id');

            $memberModel = new Model_Member();
            $memberDocumentModel = new Model_Memberdocument();
            $memberDetailModel =new Model_Memberdetails();
            $memberDocuments = $memberDocumentModel->fetchMemberDocuments("mem_id = '" . $member_id . "'");
            foreach ($memberDocuments as $_doc) {
                $folder = $this->config->UPLOAD_PATH . "member/document/";
                $docPath = $folder . $_doc['memd_doc'];
                if (file_exists($docPath)) {
                    unlink($docPath);
                }
            }
            $memberDetailModel->delete("member_id = '" . $member_id . "'");
            $memberDocumentModel->delete("mem_id = '" . $member_id . "'");
            $memberModel->delete("member_id = '" . $member_id . "'");

            $successmessage = "Member deleted successfully";
            $this->addSuccessMessage($successmessage);
            $this->_helper->redirector('list', 'member', '');
            exit;
        }
    }

     
}

   
?>
